package com.zk.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zk.entity.AllMenu;
import com.zk.entity.ResultDto;
import com.zk.mapper.AllMenuMapper;
import com.zk.service.IAllMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ljw
 * @since 2020-11-29
 */
@RestController
@RequestMapping("/zk/all-menu")
@Api(value = "菜单信息管理")
public class AllMenuController {
    @Autowired
    private IAllMenuService iAllMenuService;
    @Resource
    private AllMenuMapper allMenuMapper;

    /**
     * 增加菜单
     */
    @RequestMapping(value = "/",method = RequestMethod.POST)
    @ApiOperation(value="增加菜单", notes="test: 仅1和2有正确返回")
    public ResultDto insertAllMenu(AllMenu allMenu){
        boolean count = iAllMenuService.save(allMenu);
        return new ResultDto(200,"插入成功",count);
    }
    /**
     * 根据id删除菜单
     */
    @RequestMapping(value = "/{id}",method = RequestMethod.DELETE)
    @ApiOperation(value="删除菜单", notes="test: 仅1和2有正确返回")
    public void deleteAllMenu(@PathVariable("id") Serializable id){
        System.out.println(id);
        iAllMenuService.removeById(id);
    }

    /**
     * 根据id修改菜单
     */
    @RequestMapping(value = "/",method = RequestMethod.PUT)
    @ApiOperation(value="根据id修改菜单", notes="test: 仅1和2有正确返回")
    public void  updateById(AllMenu allMenu){
        iAllMenuService.updateById(allMenu);
    }
    /**
     * 根据id查询菜单
     */
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    @ApiOperation(value="查询id菜单信息", notes="test: 仅1和2有正确返回")
    public AllMenu  selectById(@RequestParam("id") int id){
        QueryWrapper<AllMenu> allMenuQueryWrapper = new QueryWrapper<>();
        allMenuQueryWrapper.eq("menu_id",id);
        AllMenu allMenu = iAllMenuService.getOne(allMenuQueryWrapper);
        return  allMenu;
    }

    /**
     * 查询所有菜单
     */

    @RequestMapping(value = "/",method = RequestMethod.GET)
    @ApiOperation(value="查询所有菜单信息", notes="test: 仅1和2有正确返回")
    public List<AllMenu> listAll(){
        List<AllMenu> allMenus = iAllMenuService.list(new QueryWrapper<>());
        return allMenus;
    }

    /**
     * 分页查询菜单
     */
    @RequestMapping(value = "/page",method = RequestMethod.GET)
    @ApiOperation(value="分页查询所有菜单信息", notes="test: 仅1和2有正确返回")
    public IPage<Map<String, Object>> pageInfo(){
        IPage<Map<String, Object>> page2=new Page<Map<String, Object>>(1,2);
        return allMenuMapper.selectMapsPage(page2 ,null);

    }
}

